package servlet;

import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import service.GreetingService;

public class HelloServlet extends HttpServlet{

	protected void doGet(HttpServletRequest req,HttpServletResponse resp){
		WebApplicationContext wac = WebApplicationContextUtils
				.getRequiredWebApplicationContext(getServletContext());
		GreetingService service = wac.getBean(GreetingService.class);
			try {
				OutputStream os = resp.getOutputStream();
				os.write(service.greeting().getBytes());
				os.flush();
				os.close(); 
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		
	}
}
